import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Stack;

public class Solution3 {
    public static void main(String[] args) {
        System.out.println(calculate("3+2*2"));
    }
    public static int calculate(String ss) {
        Deque<Integer> st = new ArrayDeque<>();
        char op = '+';
        int i = 0;
        int n = ss.length();
        char[] s = ss.toCharArray();

        while(i < n) {
            if(s[i] == ' ') {
                i++;
            }else if(s[i] >= '0' && s[i] <= '9') {
                int tmp = 0;
                while(i < n && s[i] >= '0' && s[i] <= '9') {
                    tmp = tmp * 10 + (s[i] - '0');
                    i++;
                }
                if(op == '+') {
                    st.push(tmp);
                }else if(op == '-') {
                    st.push(-tmp);
                }else if(op == '*') {
                    st.push(st.pop() * tmp);
                }else if(op == '/') {
                    st.push(st.pop() / tmp);
                }
            }else {
                op = s[i];
                i++;
            }
        }

        // 统计结果
        int ret = 0;
        while(!st.isEmpty()) {
            ret += st.pop();
        }
        return ret;
    }
}
